import React, { Component, createRef } from "react";

// ref可以获取dom节点
// 不能在componentDidMount之前获取
class App extends Component {
  box = createRef();

  fn = () => {
    console.log(this.box.current);
  };

  render() {
    return (
      <>
        <h2>ref获取dom节点</h2>
        <div ref={this.box}>box</div>
        <button onClick={this.fn}>btn</button>
      </>
    );
  }

  componentDidMount() {
    console.log(this.box.current);
  }
}

export default App;
